package com.itsu.app.controller;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itsu.api.controllerApi.TanhuaControllerApi;
import com.itsu.app.service.AppTanhuaService;
import com.itsu.interfaces.entity.Question;
import com.itsu.interfaces.entity.UserInfoEntity;
import com.itsu.pojo.dto.RecommendationDTO;
import com.itsu.pojo.vo.PageResult;
import com.itsu.pojo.vo.TodayBest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class TanhuaController implements TanhuaControllerApi {

    @Autowired
    AppTanhuaService appTanhuaService;

    @Override
    public ResponseEntity todayBest() {

        TodayBest todayBest = appTanhuaService.todayBest();
        return ResponseEntity.ok(todayBest);
    }

    @Override
    public ResponseEntity recommendation(RecommendationDTO recommendationDTO) {
        PageResult page = appTanhuaService.recommendation(recommendationDTO);
        return ResponseEntity.ok(page);
    }

    @Override
    public ResponseEntity queryQuestion(Integer userId) {
        Question question = appTanhuaService.queryQuestion(userId);
        return ResponseEntity.ok(question.getTxt());
    }

    @Override
    public ResponseEntity replyQuestion(Map<String, String> map) {
        String userId = map.get("userId");
        String reply = map.get("reply");
        appTanhuaService.replyQuestion(Convert.toInt(userId), reply);
        return ResponseEntity.ok(null);
    }

    /**
     * 左右滑卡片信息
     * @return
     */
    @Override
    public ResponseEntity<Object> cards() {
        List<TodayBest> list = appTanhuaService.queryCardUser();
        return ResponseEntity.ok(list);
    }

    /**
     * 个人信息
     * @param userId
     * @return
     */
    @GetMapping("{id}/personalInfo")
    public ResponseEntity<TodayBest> queryUserInfo(@PathVariable("id") Long userId) {
        TodayBest todayBest = appTanhuaService.queryUserInfo(userId);
        return ResponseEntity.ok(todayBest);
    }

    @GetMapping("{id}/love")
    public ResponseEntity<Object> likeCardUser(@PathVariable("id") Long userId) {
        appTanhuaService.likeCardUser(userId);
        return ResponseEntity.ok(null);
    }

    @GetMapping("{id}/unlove")
    public ResponseEntity<Object> unLikeCardUser(@PathVariable("id") Long userId) {
        appTanhuaService.unLikeCardUser(userId);
        return ResponseEntity.ok(null);
    }
}
